package dbUtil.handler;

import dbUtil.ResultsetHandler;
import dbUtil.Row;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class BeanListHandler<T> implements ResultsetHandler<List<T>> {
    private Class<?> clazz;
    public BeanListHandler(Class<?> clazz){
        this.clazz=clazz;
    }
    public List<T> handler(ResultSet rs) throws SQLException {
        List<T> list=new ArrayList<T>();
        while (rs.next()){
             list.add((T) Row.toBean(rs, clazz));
        }
        return list;
    }
}
